Hello, I can't determine what is causing my run-time error....I believe it has to do with freeing objects but for the life of me I don't see what I'm doing wrong..Any help would be appreciated. Thank you.
-Jim
/*
This attribute DXL was generated on 12/18/2013 21:16:02.
*/
// prevent dxl timeout dialog
pragma runLim, 0
Buffer bsz = create
void endAttributeDXL()
{
if (!null obj && attrDXLName != "")
{
obj.attrDXLName = tempStringOf(bsz)
}
delete bsz
}
void addNewLineSeparator(Buffer& b)
{
if (length(b) > 0)
{
b += "\n"
}
}
void display(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRich(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColour(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColor(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void display(Attr__ a)
{
string s = richText a
if (!null s)
{
displayRich s
}
}
//**********
// DXL generated by DOORS traceability wizard on 15 January 2013.
// Wizard version 2.0, DOORS version 9.3.0.7
pragma runLim, 0
// Global Variables.
const Regexp DILregx = regexp2 ".*/dil/.*"
const Regexp SRSregx = regexp2 ".*/srs/.*"
Skip parentobj = create ()
Skip ItmObjects = create ()
Object v = null
Object tableCell = null
Buffer str = create ()
int ItmCnt = 0
int ItemsPerLine = 0
string HyperStart = "{\\field{\\*\\fldinst HYPERLINK \""
string HyperMiddle = "\"}{\\fldrslt "
string HyperEnd = "}}"
const int MaxItemsPerLine = 2
void deleteSkip(Skip& sList)
{ // Delete nested skip list and free memory
Buffer buf
for buf in sList do {delete buf}
delete sList
} // Delete nested skip list and f
void showOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
Buffer temp = create ()
for l in all(o->"*") do {
if (name(module(l)) "" == "Validates" ||
name(module(l)) "" == "Verifies" ||
name(module(l)) "" == "child2parent" ||
name(module(l)) "" == "parent2child" ||
name(module(l)) "" == "SDM" ||
name(module(l)) "" == "See also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (fullName(module(o)) == fullName(otherMod)) {delete otherVersion; continue} // 'internal links' aka "See also"
if (!SRSregx lower(fullName(otherMod))) {
if (DILregx lower(fullName(otherMod))) {delete otherVersion; continue}
}
temp = HyperStart
temp += getLegacyURL(othero)
temp += HyperMiddle
temp += name(module(othero))
temp += "-"
temp += probeAttr_(othero, "Absolute Number")
temp += HyperEnd
put(ItmObjects, ++ItmCnt, temp, true)
delete otherVersion
}
}
void SeeAlsoOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
for l in all(o->"*") do {
if (lower(name(module(l))) "" != "see also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (module(o) != module(othero)) {delete otherVersion; continue} // 'internal links' aka "See also"
// stop infinite looping
if (find(parentobj, othero)) {
delete otherVersion
continue
} else {
put(parentobj, othero, othero, true)
}
delete otherVersion
SeeAlsoOut(othero)
}
}
if (cell(obj)) {
if (obj == (last(getRow(obj)))) {
for tableCell in (getRow(obj)) do {
// Include current object.
// Data validation against Current Object.
put(parentobj, tableCell, tableCell, true)
// Find all interm Objects.
SeeAlsoOut(tableCell)
}
}
} else {
// Include current object.
// Data validation against Current Object.
put(parentobj, obj, obj, true)
// Find all interm Objects.
SeeAlsoOut(obj)
}
for v in parentobj do {showOut(v)}
Buffer s = create (); s = ""
for str in ItmObjects do {
s += tempStringOf(str)
if (++ItemsPerLine == MaxItemsPerLine) {
ItemsPerLine = 0
if (ItmCnt-- > 1) s += "\n"
} else {
if (ItmCnt-- > 1) s += ", "
}
}
display(tempStringOf(s))
// freeing memory...
delete s
delete DILregx
delete SRSregx
delete parentobj
deleteSkip(ItmObjects)
//**********
endAttributeDXL()
EHcnck - Sat Dec 21 02:25:28 EST 2013 |
Re: run-time error help needed Hey Jim, what looks suspicious is that you put the same buffer to the ItmObjects skip list possibly
void showOut(Object o) {
....
Buffer temp = create ()
....
for l in all(o->"*") do {
temp = HyperStart
temp += ....
temp += HyperEnd
put(ItmObjects, ++ItmCnt, temp, true) // Put the same buffer here?
....
}
Which might give you a problem on the delete later. However putting the code to a module does not give me an error, even if I create some links inside the module with link module name "see also". Apart from that it is pretty hard to start looking unless you provide:
Regards, Mathias |
Re: run-time error help needed Mathias Mamsch - Sat Dec 21 14:54:37 EST 2013 Hey Jim, what looks suspicious is that you put the same buffer to the ItmObjects skip list possibly
void showOut(Object o) {
....
Buffer temp = create ()
....
for l in all(o->"*") do {
temp = HyperStart
temp += ....
temp += HyperEnd
put(ItmObjects, ++ItmCnt, temp, true) // Put the same buffer here?
....
}
Which might give you a problem on the delete later. However putting the code to a module does not give me an error, even if I create some links inside the module with link module name "see also". Apart from that it is pretty hard to start looking unless you provide:
Regards, Mathias Hi, I'm trying to produce an RTM where the parent object are hyperlinks. RPE is unable to correctly process all forms of hyperlink within DOORS(rtf) so I created a macro to parse the output file then to convert them into hyperlinks. In my original code the issue arose when going from a cell to non-cell objects. "See also" are internal links that were meant to be only reference links... but changed as the project aged. so now in some cases there are circular links and by putting them into a skip list that was my way of short circuiting if they are found then parse the skip list for the actual RTM. Please see below modified code I fixed my issue just was wondering what I was doing wrong with my original code?
/*
This attribute DXL was generated on 12/18/2013 21:16:02.
*/
// prevent dxl timeout dialog
pragma runLim, 0
Buffer bsz = create
void endAttributeDXL()
{
if (!null obj && attrDXLName != "")
{
obj.attrDXLName = tempStringOf(bsz)
}
delete bsz
}
void addNewLineSeparator(Buffer& b)
{
if (length(b) > 0)
{
b += "\n"
}
}
void display(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRich(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColour(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColor(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void display(Attr__ a)
{
string s = richText a
if (!null s)
{
displayRich s
}
}
//**********
// DXL generated by DOORS traceability wizard on 15 January 2013.
// Wizard version 2.0, DOORS version 9.3.0.7
pragma runLim, 0
// Global Variables.
const Regexp DILregx = regexp2 ".*/dil/.*"
const Regexp SRSregx = regexp2 ".*/srs/.*"
Skip parentobj = create ()
Buffer temp = create ()
Object v = null
Object tableCell = null
int ItemsPerLine = 0
const int MaxItemsPerLine = 2
void showOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
for l in all(o->"*") do {
if (name(module(l)) "" == "Validates" ||
name(module(l)) "" == "Verifies" ||
name(module(l)) "" == "child2parent" ||
name(module(l)) "" == "parent2child" ||
name(module(l)) "" == "SDM" ||
name(module(l)) "" == "See also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (fullName(module(o)) == fullName(otherMod)) {delete otherVersion; continue} // 'internal links' aka "See also"
if (!SRSregx lower(fullName(otherMod))) {
if (DILregx lower(fullName(otherMod))) {delete otherVersion; continue}
}
if (++ItemsPerLine == MaxItemsPerLine) {temp += ", "}
temp += "{\\field{\\*\\fldinst HYPERLINK \""
temp += getLegacyURL(othero)
temp += "\"}{\\fldrslt "
temp += name(module(othero))
temp += "-"
temp += probeAttr_(othero, "Absolute Number")
temp += "}}"
if (ItemsPerLine == MaxItemsPerLine) {
ItemsPerLine = 0
temp += "\n"
}
delete otherVersion
}
}
void SeeAlsoOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
for l in all(o->"*") do {
if (lower(name(module(l))) "" != "see also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (module(o) != module(othero)) {delete otherVersion; continue} // 'internal links' aka "See also"
// stop infinite looping
if (find(parentobj, othero)) {
delete otherVersion
continue
} else {
put(parentobj, othero, othero, true)
}
delete otherVersion
SeeAlsoOut(othero)
}
}
if (cell(obj)) {
if (obj == (last(getRow(obj)))) {
for tableCell in (getRow(obj)) do {
// Include current object.
// Data validation against Current Object.
put(parentobj, tableCell, tableCell, true)
// Find all interim Objects.
SeeAlsoOut(tableCell)
}
}
} else {
// Include current object.
// Data validation against Current Object.
put(parentobj, obj, obj, true)
// Find all interim Objects.
SeeAlsoOut(obj)
}
for v in parentobj do {showOut(v)}
display(tempStringOf(temp))
// freeing memory...
delete temp
delete DILregx
delete SRSregx
delete parentobj
//**********
endAttributeDXL()
VBA
Sub ReplaceLinks()
Application.ScreenUpdating = False
Dim LinkString As String
Dim LinkLength As Integer
Dim EntireString As String
Dim TextString As String
Selection.HomeKey Unit:=wdStory
Application.DisplayAlerts = wdAlertsNone
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\{\\field?*\}\}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While True
If Selection.Find.Execute Then
EntireString = Selection.Text
LinkString = Mid(EntireString, 31, InStr(31, EntireString, """") - 31)
LinkLength = Len(LinkString)
TextString = Mid(EntireString, LinkLength + 43, Len(EntireString) - LinkLength - 44)
Selection.Text = TextString
ActiveDocument.Hyperlinks.Add Selection.Range, LinkString
Else
Exit Sub
End If
Loop
Application.ScreenUpdating = True
End Sub
|
Re: run-time error help needed EHcnck - Sat Dec 21 18:22:58 EST 2013 Hi, I'm trying to produce an RTM where the parent object are hyperlinks. RPE is unable to correctly process all forms of hyperlink within DOORS(rtf) so I created a macro to parse the output file then to convert them into hyperlinks. In my original code the issue arose when going from a cell to non-cell objects. "See also" are internal links that were meant to be only reference links... but changed as the project aged. so now in some cases there are circular links and by putting them into a skip list that was my way of short circuiting if they are found then parse the skip list for the actual RTM. Please see below modified code I fixed my issue just was wondering what I was doing wrong with my original code?
/*
This attribute DXL was generated on 12/18/2013 21:16:02.
*/
// prevent dxl timeout dialog
pragma runLim, 0
Buffer bsz = create
void endAttributeDXL()
{
if (!null obj && attrDXLName != "")
{
obj.attrDXLName = tempStringOf(bsz)
}
delete bsz
}
void addNewLineSeparator(Buffer& b)
{
if (length(b) > 0)
{
b += "\n"
}
}
void display(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRich(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColour(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void displayRichWithColor(string s)
{
addNewLineSeparator(bsz)
bsz += s
}
void display(Attr__ a)
{
string s = richText a
if (!null s)
{
displayRich s
}
}
//**********
// DXL generated by DOORS traceability wizard on 15 January 2013.
// Wizard version 2.0, DOORS version 9.3.0.7
pragma runLim, 0
// Global Variables.
const Regexp DILregx = regexp2 ".*/dil/.*"
const Regexp SRSregx = regexp2 ".*/srs/.*"
Skip parentobj = create ()
Buffer temp = create ()
Object v = null
Object tableCell = null
int ItemsPerLine = 0
const int MaxItemsPerLine = 2
void showOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
for l in all(o->"*") do {
if (name(module(l)) "" == "Validates" ||
name(module(l)) "" == "Verifies" ||
name(module(l)) "" == "child2parent" ||
name(module(l)) "" == "parent2child" ||
name(module(l)) "" == "SDM" ||
name(module(l)) "" == "See also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (fullName(module(o)) == fullName(otherMod)) {delete otherVersion; continue} // 'internal links' aka "See also"
if (!SRSregx lower(fullName(otherMod))) {
if (DILregx lower(fullName(otherMod))) {delete otherVersion; continue}
}
if (++ItemsPerLine == MaxItemsPerLine) {temp += ", "}
temp += "{\\field{\\*\\fldinst HYPERLINK \""
temp += getLegacyURL(othero)
temp += "\"}{\\fldrslt "
temp += name(module(othero))
temp += "-"
temp += probeAttr_(othero, "Absolute Number")
temp += "}}"
if (ItemsPerLine == MaxItemsPerLine) {
ItemsPerLine = 0
temp += "\n"
}
delete otherVersion
}
}
void SeeAlsoOut(Object o) {
Link l = null
ModName_ otherMod = null
Object othero = null
for l in all(o->"*") do {
if (lower(name(module(l))) "" != "see also") continue
ModuleVersion otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) {delete otherVersion; continue}
othero = target l
if (null othero) {load(otherVersion,false)}
othero = target l
if (null othero) {delete otherVersion; continue}
if (isDeleted othero) {delete otherVersion; continue}
if (module(o) != module(othero)) {delete otherVersion; continue} // 'internal links' aka "See also"
// stop infinite looping
if (find(parentobj, othero)) {
delete otherVersion
continue
} else {
put(parentobj, othero, othero, true)
}
delete otherVersion
SeeAlsoOut(othero)
}
}
if (cell(obj)) {
if (obj == (last(getRow(obj)))) {
for tableCell in (getRow(obj)) do {
// Include current object.
// Data validation against Current Object.
put(parentobj, tableCell, tableCell, true)
// Find all interim Objects.
SeeAlsoOut(tableCell)
}
}
} else {
// Include current object.
// Data validation against Current Object.
put(parentobj, obj, obj, true)
// Find all interim Objects.
SeeAlsoOut(obj)
}
for v in parentobj do {showOut(v)}
display(tempStringOf(temp))
// freeing memory...
delete temp
delete DILregx
delete SRSregx
delete parentobj
//**********
endAttributeDXL()
VBA
Sub ReplaceLinks()
Application.ScreenUpdating = False
Dim LinkString As String
Dim LinkLength As Integer
Dim EntireString As String
Dim TextString As String
Selection.HomeKey Unit:=wdStory
Application.DisplayAlerts = wdAlertsNone
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\{\\field?*\}\}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While True
If Selection.Find.Execute Then
EntireString = Selection.Text
LinkString = Mid(EntireString, 31, InStr(31, EntireString, """") - 31)
LinkLength = Len(LinkString)
TextString = Mid(EntireString, LinkLength + 43, Len(EntireString) - LinkLength - 44)
Selection.Text = TextString
ActiveDocument.Hyperlinks.Add Selection.Range, LinkString
Else
Exit Sub
End If
Loop
Application.ScreenUpdating = True
End Sub
As I said, you were putting the same buffer multiple times to the Skip list:
....
Buffer temp = create ()
....
for l in all(o->"*") do {
...
put(ItmObjects, ++ItmCnt, temp, true) // Put the same buffer here?
....
}
So after that code the buffer temp that you allocated more than once could be possibly put to the skip ItmObjects a couple of times with different indices. Later when you do: ... deleteSkip(ItmObjects) ... you would try to delete that same buffer multiple times for each index. Now that you removed the problematic code its reasonable the error went away. Regards, Mathias |
Re: run-time error help needed Mathias Mamsch - Sun Dec 22 14:15:57 EST 2013 As I said, you were putting the same buffer multiple times to the Skip list:
....
Buffer temp = create ()
....
for l in all(o->"*") do {
...
put(ItmObjects, ++ItmCnt, temp, true) // Put the same buffer here?
....
}
So after that code the buffer temp that you allocated more than once could be possibly put to the skip ItmObjects a couple of times with different indices. Later when you do: ... deleteSkip(ItmObjects) ... you would try to delete that same buffer multiple times for each index. Now that you removed the problematic code its reasonable the error went away. Regards, Mathias hello, I'm confused since my key was only initialized once...how was I writting to the same spot in the skiplist and even if I did shouldn't the old info be over written? -Jim |
Re: run-time error help needed EHcnck - Sun Dec 22 17:15:30 EST 2013 hello, I'm confused since my key was only initialized once...how was I writting to the same spot in the skiplist and even if I did shouldn't the old info be over written? -Jim Well what you did was something like that:
Skip sk = create();
int cnt = 0
Buffer buf = create();
buf = "First" ; put(sk, cnt++, buf);
buf = "Second"; put(sk, cnt++, buf);
buf = "Third" ; put(sk, cnt++, buf);
for buf in sk do {
int index = (key sk) int;
print "Skip at index: " index " BUF = " buf "\n"
}
/* prints:
Skip at index: 0 BUF = Third
Skip at index: 1 BUF = Third
Skip at index: 2 BUF = Third
*/
Why because the skip list will not store the contents of the buffer! It will only store a reference to the buffer. And this same reference is now stored at index 0..3, but all references go to the same buffer! It is the same than writing: Buffer buf = create(); Buffer buf2 = buf Buffer buf3 = buf2 buf = "Hallo"; // all buffers reference the same instance, all buffers will read "Hallo" So what you probably want instead of the above is:
Skip sk = create();
int cnt = 0
Buffer buf = null
// Create a new buffer for every piece of content
buf = create(); buf = "First" ; put(sk, cnt++, buf);
buf = create(); buf = "Second"; put(sk, cnt++, buf);
buf = create(); buf = "Third" ; put(sk, cnt++, buf);
for buf in sk do {
int index = (key sk) int;
print "Skip at index: " index " BUF = " buf "\n"
}
/* prints:
Skip at index: 0 BUF = First
Skip at index: 1 BUF = Second
Skip at index: 2 BUF = Third
*/
So long story short: The Buffer create() needs to go into the loop. Regards, Mathias
|